/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facade;

import entities.Material;
import entities.Product;
import entities.Pyme;
import java.util.Date;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Andrés Felipe
 */
@Stateless
@Remote(ProductFacadeRemote.class)
public class ProductFacade extends AbstractFacade<Product> implements ProductFacadeRemote {
    @PersistenceContext(unitName = "Javeriana.EJB.EstimatorPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ProductFacade() {
        super(Product.class);
    }

    @Override
    public void editDataMaster(int idProduct, String dataMaster) {
        Product product = this.find(idProduct);
        product.setDatamaster(dataMaster);
        this.edit(product);
    }

    @Override
    public void addProduct(String nombre, String dataMaster, double price,double quantity, double capacity, Date productionAbleDate, double productionTime, int toSell, int pymeIdentification , Material typematerial) {
        
        if (!typematerial.getTypematerial().equals(""))
        {
            Product product = new Product(nombre,dataMaster, price, quantity, capacity, productionAbleDate, toSell, quantity, productionTime , typematerial);
            product.setPymeidentification(new Pyme(pymeIdentification));
            this.create(product);
    
        } 
        else
        {
            Product product = new Product(nombre,dataMaster, price, quantity, capacity, productionAbleDate, toSell, quantity, productionTime , null);
            product.setPymeidentification(new Pyme(pymeIdentification));
            this.create(product);
        }
    }
}
